<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 无限极栏目分类
 * @param $data
 * @param int $parent
 * @param int $level
 * @return array
 */
function loop($data,$parent=0,$level=0){
    static $arr=[];
    foreach ($data as $k=>$v){
        if($v['pid']==$parent) {
            $v['level'] = $level;
            $arr[]=$v;
            unset($data[$k]);
            loop($data, $v['id'], $level + 1);
        }
    }
    return $arr;
}

/**
 * 无限循环层级数组
 * @param $arr
 * @return array
 */
function loop_tree($arr){
    $item=[];
    foreach ($arr as $k=>$v){
        $item[$v['id']]=$v;
    }
    $tree=[];
    foreach ($item as $key=>$value){
        if(isset($item[$value['pid']])){
            $item[$value['pid']]['son'][]=&$item[$key];
        }else{
            $tree[]=&$item[$key];
        }
    }
    return $tree;
}

function getChildInfo($id,$arr){
    static $item=[];
    foreach ($arr as $key=>$value){
        if($value['pid']==$id){
            $item[]=$value;
            getChildInfo($value['id'],$arr);
        }
    }
    return $item;
}


























